﻿using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using BBMS.DLL.Base;
using System.Collections;
namespace BBMS.DLL.DataContract
{
    public class NhaCungCapList : BBMS.DLL.Base.ObjectList
    {
        public override void LoadData()
        {
            NhaCungCap ncc = new NhaCungCap();
            if (hash == null) hash = new System.Collections.Hashtable();
            hash.Clear();
            try
            {
                MySqlConnection con = new MySqlConnection(Base.Config.ConnectionString());
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "select * from " + ncc.TableName;
                MySqlDataReader rd = cmd.ExecuteReader();

                while (rd.Read())
                    this.Add(ncc.DataReaderToObject(rd));

                rd.Close();
                rd.Dispose();
                con.Close();
                con.Dispose();
            }
            catch
            {
                this.hash.Clear();
            }
        }

        public static System.Collections.ArrayList getAllMaNCC()
        {
            NhaCungCap ncc = new NhaCungCap();
            ArrayList arrRet = new ArrayList();
            try
            {
                MySqlConnection con = new MySqlConnection(Base.Config.ConnectionString());
                con.Open();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "select Ma, Ten from " + ncc.TableName;
                MySqlDataReader rd = cmd.ExecuteReader();

                while (rd.Read())
                    arrRet.Add(new KeyValuePair(rd["Ma"].ToString(), rd["Ten"].ToString()));
                // this.Add(nv.DataReaderToObject(rd));

                rd.Close();
                rd.Dispose();
                con.Close();
                con.Dispose();
            }
            catch
            {

            }

            return arrRet;
        }
    }
}
